import api from '@/services/api';
import { Role } from '../users/types';
import type{ InputGetClassList } from '@/services/courses/types';

async function getClassList(input:InputGetClassList) {
  let url = '';
  if (input.role === Role.Student) {
    url = `/api/student/${input.id}/courses/`;
  } else if (input.role === Role.Teacher) {
    url = `/api/teacher/${input.id}/courses/`;
  }

  return await api.get(url);
}

// 获取某课程的教师信息
async function getTeacherInfo(courseId: number, studentId: number) {
  return await api.post(`/api/student/${studentId}/course-teacher/`, {c_id: courseId});
}

// 获取某课程的课程介绍
async function getCourseInfo(courseId: number, studentId: number) {
  return await api.post(`/api/student/${studentId}/course-introduction/`, {c_id: courseId});
}

// 获取某课程的课程大纲
async function getSyllabus(courseId: number, studentId: number) {
  return await api({
    method: 'post',
    url:`/api/student/${studentId}/course-outline/`,
    data: {
      c_id: courseId,
    },
    responseType: 'blob',
  });
}

async function modifySyllabus(courseId: number, teacherId: number, File: File) {
  return await api({
    method: 'post',
    url:`/api/teacher/${teacherId}/adjust-course-outline/`,
    data: File,
  });
}

// 获取某课程的教学日历
async function getCalendar(courseId: number) {
  return await api.get(`/api/course/${courseId}/calendar/`);
}

// 获取某课程的课程作业
async function getHomework(courseId: number) {
  return await api.get(`/api/course/${courseId}/homework/`);
}

// 获取某课程的课程资源
async function getResource(courseId: number) {
  return await api.get(`/api/course/${courseId}/resource/`);
}

// 获取某课程的课程讨论
async function getDiscussion(courseId: number) {
  return await api.get(`/api/course/${courseId}/discussion/`);
}


export default {
  getClassList,
  getTeacherInfo,
  getCourseInfo,
  getSyllabus,
  getCalendar,
  getHomework,
  getResource,
  getDiscussion,
  modifySyllabus,
}
